﻿/**
作者：高彩红
时间：209-11-24
功能：实现用户个人信息修改
**/
var Obj = new Object();
var id = "";
function ShowMain() {

    GetUserID();
    //GetUser();
}
//获取“用户ID”
function GetUserID() { 
var url = encodeURI(SBasePath + '/action/UsersManage/GetUserID.aspx');
var pars = encodeURI('');
var myAjax = new Ajax.Request(url, { method: 'get', parameters: pars, onComplete: sGetUserID, onFailure: fGetUserID });
}
function sGetUserID(o) {

    var root = o.responseXML.documentElement;
    id = GetXmlData(root, "Value");
    GetUser();

}
function fGetUserID() {

}
//获取"信息"
function GetUser() {
    var url = encodeURI(SBasePath + '/action/UsersManage/GetUser.aspx?id=' + id);
    var pars = encodeURI('');
    var myAjax = new Ajax.Request(url, { method: 'get', parameters: pars, onComplete: sGetUser, onFailure: fGetUser });
}

//获取"信息"成功
function sGetUser(o) {
    Obj = MapAdmin_Users(o);
    ShowEdit();
}
function fGetUser() {
}

//提交
function sbmt() {
    if (CheckForm()) {
        var url = encodeURI(SBasePath + '/action/usersmanage/UserEdit.aspx');
        var myAjax = new Ajax.Request(url, { method: 'post', parameters: Form.serialize("formsubmit"), onComplete: sFormSubmit, onFailure: fFormSubmit });
    }
};

//提交成功
var sFormSubmit = function(o) {
    var root = o.responseXML.documentElement;
    var OutputFlag = GetXmlData(root, "Value");
    var alt = GetXmlData(root, "Alt");
    if (OutputFlag == "true") {
        MsgDlgLocal(alt);
        //window.top.frames["Content"].location.href = SBasePath + '/htm/UsersManage/UserEdit.htm';
    }
    else {
        MsgDlg(alt);
        window.history(-1);
    }

};

//提交失败
var fFormSubmit = function(o) {
};


var CheckForm = function() {

    var fobj = $("formsubmit");

    if (Trim(fobj.UserName.value) == "") {
        $("UserNamediv").style.display = "";
        return false;
    }
    else {
        $("UserNamediv").style.display = "none";
    }

    if (Trim(fobj.OPwd.value) == "") {
        $("OfPwd").style.display = "";
        return false;
    }
    else {
        $("OfPwd").style.display = "none";
        if (GetStrLength(Trim(fobj.OPwd.value)) < 6) {
            $("OPwdxy").style.display = ""
            return false;
        } else {
        $("OPwdxy").style.display = "none"
        }

        if (GetStrLength(Trim(fobj.OPwd.value)) > 20) {
            $("OPwddy").style.display = ""
            return false;
        } else {
        $("OPwddy").style.display = "none"
        }
    }
    
    if (Trim(fobj.Pwd.value) == "") {
        $("fPwd").style.display = "";
        return false;
    }
    else {
        $("fPwd").style.display = "none";
        if (GetStrLength(Trim(fobj.Pwd.value)) < 6) {
            $("Pwdxy").style.display = ""
            return false;
        } else {
            $("Pwdxy").style.display = "none"
        }

        if (GetStrLength(Trim(fobj.Pwd.value)) > 20) {
            $("Pwddy").style.display = ""
            return false;
        } else {
            $("Pwddy").style.display = "none"
        }
    }


    if (Trim(fobj.RPwd.value) != Trim(fobj.Pwd.value)) {
        $("sPwd").style.display = "";
        return false;
    } else {
        $("sPwd").style.display = "none";
    }

    if (Trim(fobj.DisName.value) == "") {
        $("DisplayName").style.display = "";
        return false;
    } else {
        $("DisplayName").style.display = "none";
    }
    return true;
};

function OutName() {
    if (document.getElementById("UserName").value == "") {
        $("UserNamediv").style.display = "";
        return false;
    } else {
        $("UserNamediv").style.display = "none";
        var url = encodeURI(SBasePath + '/action/UsersManage/UsersExist.aspx');
        var pars = encodeURI("?UserName=" + document.getElementById("UserName").value);
        var myAjax = new Ajax.Request(url, { method: 'get', parameters: pars, onComplete: sFormSubmitExist, onFailure: fFormSubmitExist });
    }
}
function sFormSubmitExist(o) {

    var root = o.responseXML.documentElement;

    var OutputFlag = GetXmlData(root, "Value");
    if (OutputFlag == "True") {
        $("UserNameExist").style.display = "";
        return false;
    }
    else {
        $("UserNameExist").style.display = "none";
        return true;
    }

}

function fFormSubmitExist() {

}
function ShowEdit() {
    var str = "";
    str += '<form id="formsubmit">';
    str += '<input type="hidden" name="hidUser" value="' + id + '"/>';
    str += '<table width="100%" height="100%" border="0" align="center" cellpadding="0" cellspacing="0">';
    str += '<tr>';
    str += '    <td height="30">';
    str += '        <table width="100%" border="0" cellspacing="0" cellpadding="0">';
    str += '            <tr>';
    str += '                <td width="15" height="30" class="tab03">';
    str += '                </td>';
    str += '                <td class="tab05">';
    str += '                    <div class="title1" style="padding-top: 2px">';
    str += '                        <img src="../../img/1.gif" height="20" width="19" />个人信息修改</div>';
    str += '                </td>';
    str += '                <td width="14" class="tab07"></td>';
    str += '            </tr>';
    str += '        </table>';
    str += '    </td>';
    str += '</tr>';
    str += '<tr>';
    str += '    <td>';
    str += '        <table width="100%" border="0" cellspacing="0" cellpadding="0">';
    str += '            <tr>';
    str += '                <td width="9" class="tab12"></td>';
    str += '                <td bgcolor="#f3ffe3">';
    str += '                    <table width="100%" border="0" cellspacing="0" cellpadding="0">';
    str += '                        <tr>';
    str += '                            <td class="k_hui">';
    str += '                                <table width="97%" border="0" cellspacing="0" cellpadding="0" align="center">';
    str += '                                    <tr height="38">';
    str += '                                        <td height="30" width="12%" style="padding-left: 5px">';
    str += '                                            用户名：';
    str += '                                        </td>';
    str += '                                        <td width="25%">';
    str += '                                            <input type="text" readonly name="UserName" id="UserName" class="wbk" value="' + Obj.UserName + '" />';
    str += '                                        </td>';
    str += '                                        <td width="52%" class="zw">';
    str += '                                            <div alght="right" class="clew" id="UserNamediv" style="display:none">';
    str += '                                                <img src="../../images/lamp.gif" width="15" height="16" align="absmiddle" />用户名不能为空！</div>';
    str += '                                            <div alght="right" class="clew" id="UserNameExist" style="display:none">';
    str += '                                                <img src="../../images/lamp.gif" width="15" height="16" align="absmiddle" />用户名已存在！</div>';
    str += '                                        </td>';
    str += '                                    </tr>';
    str += '                                    <tr height="38">';
    str += '                                        <td height="30" width="12%" style="padding-left: 5px">';
    str += '                                            旧&nbsp;&nbsp;密&nbsp;&nbsp;码：';
    str += '                                        </td>';
    str += '                                        <td widht="25%">';
    str += '                                            <input type="password" name="OPwd" id="OPwd" class="wbk" />';
    str += '                                        </td>';
    str += '                                        <td width="52%" class="zw">';
    str += '                                            <div alght="right" class="clew" id="OfPwd" style="display:none">';
    str += '                                                <img src="../../images/lamp.gif" width="15" height="16" align="absmiddle" />密码不能为空！</div>';
    str += '                                            <div alght="right" class="clew" id="OPwdxy" style="display:none">';
    str += '                                                <img src="../../images/lamp.gif" width="15" height="16" align="absmiddle" />密码不能小于6个字符！</div>';
    str += '                                            <div alght="right" class="clew" id="OPwddy" style="display:none">';
    str += '                                                <img src="../../images/lamp.gif" width="15" height="16" align="absmiddle" />密码不能大于20个字符！</div>';
    str += '                                        </td>';
    str += '                                    </tr>';
    str += '                                    <tr height="38">';
    str += '                                        <td height="30" width="12%" style="padding-left: 5px">';
    str += '                                            新&nbsp;&nbsp;密&nbsp;&nbsp;码：';
    str += '                                        </td>';
    str += '                                        <td widht="25%">';
    str += '                                            <input type="password" name="Pwd" id="Pwd" class="wbk" />';
    str += '                                        </td>';
    str += '                                        <td width="52%" class="zw">';
    str += '                                            <div alght="right" class="clew" id="fPwd" style="display:none">';
    str += '                                                <img src="../../images/lamp.gif" width="15" height="16" align="absmiddle" />密码不能为空！</div>';
    str += '                                            <div alght="right" class="clew" id="Pwdxy" style="display:none">';
    str += '                                                <img src="../../images/lamp.gif" width="15" height="16" align="absmiddle" />密码不能小于6个字符！</div>';
    str += '                                            <div alght="right" class="clew" id="Pwddy" style="display:none">';
    str += '                                                <img src="../../images/lamp.gif" width="15" height="16" align="absmiddle" />密码不能大于20个字符！</div>';
    str += '                                        </td>';
    str += '                                    </tr>';
    str += '                                    <tr height="38">';
    str += '                                        <td height="30" width="12%" style="padding-left: 5px">';
    str += '                                            确认密码：';
    str += '                                        </td>';
    str += '                                        <td widht="25%">';
    str += '                                            <input type="password" name="RPwd" id="RPwd" class="wbk" />';
    str += '                                        </td>';
    str += '                                        <td width="52%" class="zw">';
    str += '                                            <div alght="right" class="clew" id="SPwd" style="display:none">';
    str += '                                                <img src="../../images/lamp.gif" width="15" height="16" align="absmiddle" />两次密码不一致！</div>';
    str += '                                        </td>';
    str += '                                   </tr>';
    str += '                                    <tr height="38">';
    str += '                                        <td height="30" width="12%" style="padding-left: 5px">';
    str += '                                            真实姓名：';
    str += '                                        </td>';
    str += '                                        <td widht="25%">';
    str += '                                            <input type="text" name="DisName" value=' + Obj.DisplayName + ' id="DisName" class="wbk" />';
    str += '                                        </td>';
    str += '                                        <td width="52%" class="zw">';
    str += '                                            <div alght="right" class="clew" id="DisplayName" style="display:none">';
    str += '                                                <img src="../../images/lamp.gif" width="15" height="16" align="absmiddle" />真实姓名不能为空！</div>';
    str += '                                        </td>';
    str += '                                   </tr>';
    str += '                                    <tr height="38">';
    str += '                                        <td height="30" width="12%" style="padding-left: 5px">';
    str += '                                            办公电话：';
    str += '                                        </td>';
    str += '                                        <td widht="25%">';
    str += '                                            <input type="text" name="tel"  value="' + Obj.OfficePhone + '" id="tel" class="wbk" />';
    str += '                                        </td>';
    str += '                                        <td width="52%" class="zw">';
    str += '                                        </td>';
    str += '                                    </tr>';
    str += '                                    <tr height="38">';
    str += '                                        <td height="30" width="12%" style="padding-left: 5px">';
    str += '                                            移动电话：';
    str += '                                        </td>';
    str += '                                        <td widht="25%">';
    str += '                                            <input type="text" value="' + Obj.MobilePhone + '" name="mobile" id="mobile" class="wbk" />';
    str += '                                        </td>';
    str += '                                        <td width="52%" class="zw">';
    str += '                                        </td>';
    str += '                                    </tr>';
    str += '                                    <tr height="38">';
    str += '                                        <td height="30" width="12%" style="padding-left: 5px">';
    str += '                                            用户地址：';
    str += '                                        </td>';
    str += '                                        <td widht="25%">';
    str += '                                            <input type="text" name="address"  value="' + Obj.Address + '" id="address" style="height: 18px; width: 250px; border: solid 1px #cadcb2;" />';
    str += '                                        </td>';
    str += '                                        <td width="52%" class="zw">';
    str += '                                        </td>';
    str += '                                    </tr>';
    str += '                                    <tr height="38">';
    str += '                                        <td height="30" width="12%" style="padding-left: 5px">';
    str += '                                            用户简介：';
    str += '                                        </td>';
    str += '                                        <td widht="25%">';
    str += '                                            <textarea name="yhjj" id="yhjj" cols="50" rows="11" style="height: 100px; width: 250px; border: solid 1px #cadcb2;">' + Obj.Remark + '</textarea>';
    str += '                                        </td>';
    str += '                                        <td width="52%" class="zw">';
    str += '                                        </td>';
    str += '                                    </tr>';
    str += '                                    <tr height="38">';
    str += '                                        <td colspan="2" style="padding-left: 25px" height="30">';
    str += '                                             <input name="提交" type="button" class="bg_g" style="height: 22px; width: 60px; border: solid 1px #cadcb2;"value="提交" onclick="sbmt()" />';
    str += '                                            &nbsp;&nbsp;<input name="重置" type="reset" class="bg_g" style="height: 22px; width: 60px;border: solid 1px #cadcb2;" value="重置" />';
    str += '                                        </td>';
    str += '                                        <td width="52%" class="zw">';
    str += '                                        </td>';
    str += '                                    </tr>';
    str += '                                </table>';
    str += '                             </td>';
    str += '                        </tr>';
    str += '                    </table>';
    str += '                </td>';
    str += '                <td width="9" class="tab16">';
    str += '                </td>';
    str += '            </tr>';
    str += '        </table>';
    str += '    </td>';
    str += '</tr>';
    str += '<tr>';
    str += '    <td height="29">';
    str += '        <table width="100%" border="0" cellspacing="0" cellpadding="0">';
    str += '            <tr>';
    str += '                <td width="15" height="29" class="tab20">';
    str += '                </td>';
    str += '                <td class="tab21">';
    str += '                    &nbsp;';
    str += '                </td>';
    str += '                <td width="14" class="tab22">';
    str += '                </td>';
    str += '            </tr>';
    str += '        </table>';
    str += '    </td>';
    str += '</tr>';
    str += '</table>';
    str += '</form>';
    $("UserEdit").innerHTML = str;
}